<template>
	<!-- 项目 -->
	<view class="goods-item">
	  <!-- 左侧商品图片 -->
	    <view class="goods-item-left">
          <radio :checked="item.goods_state" color="#C00000" v-if="showRadio" @click="radioChangeHandler"></radio>
	      <image :src="item.goods_small_logo||defaultPic" mode="" class="goods-pic"></image>
	    </view>
	    <!-- 右侧信息区域 -->
	    <view class="goods-item-right">
	      <!-- 商品标题 -->
	      <view class="goods-name">{{item.goods_name}}</view>
	      <view class="goods-info-box">
	        <!-- 商品价格 -->
	        <view class="goods-price">￥{{item.goods_price | tofixed}}</view>
	      </view>
	    </view>
	  
	</view>
</template>

<script>
	export default {
    props:{
      item:{
        type:Object,
        //默认值是一个空对象
        default:{}
      },
      showRadio:{
        type:Boolean,
        defult:false
      }
      
    },
    
		data() {
			return {
    // 如果有些图片没有地址我们可以给他加一个默认的地址
		defaultPic:'https://img1.baidu.com/it/u=573448845,1736698023&fm=253&fmt=auto&app=138&f=JPEG'
			};
		},
    methods:{
      radioChangeHandler(){
        // 调用外部传过来的函数，同时将商品的id和state这些数据传递给radio-change这个函数
        this.$emit('radio-change',{
          goods_id:this.item.goods_id,
          goods_state:!this.item.goods_state
        })
      }
    },
       //过滤器,处理数值
    filters:{
     tofixed(num){ 
      return Number(num).toFixed(2)//将这个通过管道运算符渲染到页面
    }
    },
	}
</script>

<style lang="scss">
.goods-item{
  display: flex;
  padding: 10px 5px;
  border-bottom: 1px solid #f0f0f0;
  .goods-item-left{
    margin-right: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .goods-pic{
      width: 100px;
      height: 100px;
      // 防止有空隙
      display: block;
    }
  }
  .goods-item-right{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .goods-name{
      font-size: 13px;
    }
    .goods-info-box{
      .goods-price{
        color: #C00000;
        font-size: 16px;
      }
    }
  }
}
</style>
